package io.renren.modules.live.service.impl;

import io.renren.modules.live.vo.FanweStationMessageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.live.dao.FanweStationMessageDao;
import io.renren.modules.live.entity.FanweStationMessageEntity;
import io.renren.modules.live.service.FanweStationMessageService;


@Service("fanweStationMessageService")
public class FanweStationMessageServiceImpl extends ServiceImpl<FanweStationMessageDao, FanweStationMessageEntity> implements FanweStationMessageService {

    @Autowired(required = false)
    FanweStationMessageDao fanweStationMessageDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<FanweStationMessageEntity> page = this.page(
                new Query<FanweStationMessageEntity>().getPage(params),
                new QueryWrapper<FanweStationMessageEntity>()
        );

        return new PageUtils(page);
    }
    /**
     * 管理员查看系统消息列表
     * @param fanweStationMessageVo
     * @return
     */
    @Override
    public Map<String,Object> selectStationMessageList(FanweStationMessageVo fanweStationMessageVo) throws Exception{
        Map<String,Object> map=new HashMap<>();
        fanweStationMessageVo.setPageIndex((fanweStationMessageVo.getPageIndex()-1)*fanweStationMessageVo.getPageSize());
        List<FanweStationMessageEntity> fanweStationMessageEntities = fanweStationMessageDao.selectStationMessageList(fanweStationMessageVo);
        Integer integer = fanweStationMessageDao.selectStationMessageListcount(fanweStationMessageVo);
        map.put("fanweStationMessageEntities",fanweStationMessageEntities);
        map.put("count",integer);
        return map;
    }
    /**
     * 管理员查看系统消息
     * @param id
     * @return
     */
    @Override
    public FanweStationMessageEntity selectStationMessage(String id) throws Exception{
        FanweStationMessageEntity fanweStationMessageEntity = fanweStationMessageDao.selectStationMessage(id);
        return fanweStationMessageEntity;
    }

    /**
     *管理员添加或修改系统消息
     * @param fanweStationMessageEntity
     * @return
     */
    @Override
    public Integer insertAndupdateStationMessage(FanweStationMessageEntity fanweStationMessageEntity) throws Exception{
        Integer integer=null;
        if(fanweStationMessageEntity.getId()==null ){
            integer = fanweStationMessageDao.insertStationMessage(fanweStationMessageEntity);
        }else{
            integer = fanweStationMessageDao.updateStationMessage(fanweStationMessageEntity);
        }
        return integer;
    }


    /**
     * 管理员删除系统消息
     * @param id
     * @return
     */
    @Override
    public Integer deleteStationMessage(String id) throws Exception{
        Integer integer = fanweStationMessageDao.deleteStationMessage(id);
        return integer;
    }

}